home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-07-16 | 2.7 KB | 84 lines | [TEXT/CWIE] |
- // ===========================================================================
- // CFitness.cp ©1995-97 Timo Eloranta All rights reserved.
- // ===========================================================================
- // This class is used for storing the fitness of a single graph drawing,
- // as well as for comparing the quality of different drawings.
-
- // Most of the stuff is inlined and located in CFitness.h...
-
- #include "CFitness.h"
- #include <PP_Constants.h>
-
- // === Static Member Variables ===
-
- SEvaluation* CFitness::sEvaluation = nil;
-
- // ---------------------------------------------------------------------------
- // • CFitness
- // ---------------------------------------------------------------------------
- // Constructor.
-
- CFitness::CFitness()
- {
- SetCrossings( 0L );
- SetEdgeStuff( 0L );
- SetMinDistance ( 0L );
- }
-
- // ---------------------------------------------------------------------------
- // • operator=
- // ---------------------------------------------------------------------------
-
- CFitness &
- CFitness::operator=( const CFitness & inFitness)
- {
- mCrossings = inFitness.mCrossings;
- mEdgeDeviation = inFitness.mEdgeDeviation;
- mMinNodeDistance = inFitness.mMinNodeDistance;
- mMinDistSum = inFitness.mMinDistSum;
-
- mSecondValue = inFitness.mSecondValue;
-
- return *this;
- }
-
- // ---------------------------------------------------------------------------
- // • SetMinDistance
- //
- // Called by: CFitness::CFitness
- // CGraphDrawing::Evaluate
- // CGraphNodes::BruteForceClosestPairs
- // ---------------------------------------------------------------------------
- // Stores the smallest distance between a pair of nodes (inMinDist)
- // and the sum of minimum node-to-node distances (inMinDistSum).
- // Also calculates the fitness function value according to multipliers
- // which can be set in the Evaluation dialog.
-
- void
- CFitness::SetMinDistance( Int32 inMinDist, Int32 inMinDistSum,
- Int16 inNodes, Int16 inGridSize )
- {
- // If the minimum distances have not been calculated (in order to save
- // time...), this function is called with the inMinDist parameter set
- // to 0 (which is not normally possible!). In this case we ignore the
- // other parameters and set the mSecondValue to something *very* small...
-
- if ( inMinDist ) {
-
- mMinNodeDistance = inMinDist;
- mMinDistSum = inMinDistSum;
-
- mSecondValue =
- ( (sEvaluation -> multip1) * mMinDistSum) -
- ( (sEvaluation -> multip2) * mEdgeDeviation) -
- ( ((sEvaluation -> multip3) * mEdgeDeviation) /
- ((sEvaluation -> multip4) * mMinNodeDistance) ) +
- ( (inNodes / (sEvaluation -> multip5) ) *
- mMinNodeDistance * mMinNodeDistance ) -
- ( (sEvaluation -> multip6) * mCrossings *
- (inGridSize * inGridSize / (sEvaluation -> multip7) ) );
-
- } else
- mSecondValue = min_Int32;
- }
-